package com.fucking.great.context.common.db;

import cn.hutool.db.handler.RsHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 处理为字符串结果，当查询结果为单个字符串时使用此处理器
 *
 * @author  weibaohui
 */
public class RowHandler implements RsHandler<List<Object>> {
    private static final long serialVersionUID = -5296733366845720383L;

    public static final RowHandler ROW = new RowHandler(1);
    
    int columnIndex;

    public RowHandler(int columnIndex) {
        this.columnIndex = columnIndex;
    }

    @Override
    public List<Object> handle(ResultSet rs) throws SQLException {
        List<Object> list = new ArrayList<>();
        while (rs.next()){
            list.add( rs.getObject(columnIndex) );
        };
        return list;
    }
}